package com.PictureSite.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.PictureSite.controller.PictureSitePostController;
import com.PictureSite.model.PictureSitePostModel;

@SuppressWarnings("serial")
public class PictureSitePostServlet extends PictureSiteCommonServlet {

	private PictureSitePostController controller;
	
	private PictureSitePostModel model = new PictureSitePostModel();
	
	private static String view = "post.html";
	private static String errorView = "errorPage.html";
	
	@Override
	public void init() throws ServletException {
		super.init();
		this.controller = new PictureSitePostController(getDataStore());
	}
	
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		try {
			controller.loadSinglePost(model,req, resp);
			controller.bindModel(model, view, resp);
		} catch (Exception e) {
			try {
				controller.bindModel(model, errorView, resp);
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
	}

}
